var map = echarts.init(document.getElementById('about_map'));
/*城市数据*/
var add=[],dataN=[],dataS=[];
$.post('/tradi/about/getDomainList.html',function(data){
    if(data.code==1){
        dataS=data.data.province_list;
        add=data.data.city_list;
        dataN=data.data.sort_list;
        /*省会坐标*/
        var geoCoordMap = {
            '1': [121.29, 31.14],
            '2': [123.25, 41.48],
            '3': [115.54, 39.55],
            '4': [114.68, 38.02],
            '5': [112.34, 37.52],
            '6': [117.8, 35.38],
            '7': [103.51, 36.04],
            '8': [108.57, 34.17],
            '9': [104.04, 30.40],
            '10': [102.42, 25.04],
            '11': [106.42, 26.35],
            '12': [112.59, 28.12],
            '13': [120.10, 30.16],
            '14': [113.14, 23.08],
            '15': [108.19, 22.48],
            '16': [118.46, 32.03],
            '17': [114.07, 22.33],
            '18': [113.40, 34.46],
            '19': [106.33, 29.35],
            '20': [117.17, 31.52],
            '21': [114.17, 30.35],
            '22': [115.55, 28.40],
            '23': [119.18, 26.05],
            '24':[116.81,38.89],
            '25':[126.53,45.81],
            '26':[125.33,43.82],
            '27':[111.70,40.90],
            '28':[100.71,35.74],
            '29':[87.62,43.83],
            '30':[91.11,29.66],
            '31':[105.25,37.49],
            '32':[109.23,19.05],
            '33':[113.56,22.17],
            '34':[120.67,24.02]
        };
        function convertData(data) {
            var res = [];
            for (var i = 0; i < data.length; i++) {
                var geoCoord = geoCoordMap[data[i].name];
                if (geoCoord) {
                    res.push({
                        name: data[i].name,
                        value: geoCoord.concat(data[i].value)
                    });
                }
            }
            return res;
        }

        option = {
            tooltip: {
                trigger: 'item',
                backgroundColor: 'rgba(0, 0, 0, 0.6)',
                borderColor: '#000000',
                showDelay: 0,
                hideDelay: 0,
                padding: 20,
                confine:true,
                /*enterable: true,*/
                transitionDuration: 0,
                extraCssText: 'z-index:100',
                formatter: function (params, ticket, callback) {
                    //显示内容
                    var res = '';
                    /*var name = params.name;
                     var value = params.value;*/
                    for (var i = 0; i < add.length; i++) {
                        if (add[i].n == params.value) {
                            for(var j=0;j<add[i].b.length;j++){
                                if(add[i].b[j].city==null){
                                    res='';
                                }else{
                                    if(j!=add[i].b.length-1){
                                        if(add[i].b[j].city=='深圳'){
                                            res+='<h3 style="padding:0.5em 0 0.2em">'+add[i].b[j].city+'</h3>'+'<p>地址：'+add[i].b[j].address+'</p>'+'<p>全国热线：'+add[i].b[j].tel+'</p><hr style="margin-top:1em;color:#FFF;opacity:0.3"/>';
                                        }else{
                                            res+='<h3 style="padding:0.5em 0 0.2em">'+add[i].b[j].city+'</h3>'+'<p>地址：'+add[i].b[j].address+'</p>'+'<p>电话：'+add[i].b[j].tel+'&nbsp;&nbsp;'+add[i].b[j].name+'</p><hr style="margin-top:1em;color:#FFF;opacity:0.3"/>';
                                        }
                                    }else{
                                        res+='<h3 style="padding:0.5em 0 0.2em">'+add[i].b[j].city+'</h3>'+'<p>地址：'+add[i].b[j].address+'</p>'+'<p>电话：'+add[i].b[j].tel+'&nbsp;&nbsp;'+add[i].b[j].name+'</p>';
                                    }
                                }
                            }
                            return res;
                        }
                    }
                }
            },
            visualMap: {
                min: 0,
                max: 1500,
                left: '-100%',
                top: 'bottom',
                text: ['High', 'Low'],
                seriesIndex: [1],
                inRange: {
                    color: ['#c2a97b', '#c2a97b']
                },
                calculable: false
            },
            geo: {
                map: 'china',
                roam: 'move',
                // scaleLimit:{
                //   max:'1.2',
                //   min:'0.7'
                // },
                label: {
                    normal: {
                        show: true,
                        textStyle: {
                            color: '#333333'
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        borderColor: '#ffffff',
                        color: '#c2a97b'
                    },
                    emphasis: {
                        areaColor: '#886b36',
                        shadowOffsetX: 0,
                        shadowOffsetY: 0,
                        shadowBlur: 20,
                        borderWidth: 0,
                        shadowColor: 'rgba(0, 0, 0, 0)'
                    }
                }
            },
            series: [{
                type: 'scatter',
                coordinateSystem: 'geo',
                data: convertData(dataN),
                symbolSize: 0,
                symbolRotate: 0,
                symbolOffset: ['100%', '-100%'],
                label: {
                    normal: {
                        formatter: '{b}',
                        position: 'top',
                        show: false,
                        textStyle: {
                            color: '#000000',
                            fontSize: 12
                        }

                    },
                    emphasis: {
                        show: false
                    }
                },
                itemStyle: {
                    normal: {
                        color: '#000000'
                    }
                }
            }, {
                name: '',
                type: 'map',
                geoIndex: 0,
                tooltip: {
                    show: true
                },
                data: dataS
            }]
        };
        map.setOption(option);

    }else{
        console.log(data.msg);
    }
},"json");
